<?php
include("template_top.php");
?>
<h1>K-103 Business Lab Control Center</h1>
<p>
<table width="100%">
	<tr>
	<td>
	<h4>Sign In Verification</h4>
    <?php
	$CONFIG['current_mysql_credentials']['mysql_database'] = 'k103';
	db::disconnect();
	$sql = "SELECT * FROM `tbKLabVisits` WHERE `sVerified` = 0";
	$q = db::Query($sql);
	$row = $q->fetch();
	if(isset($_POST['bannerid'])){
		if(md5($row['sBannerID']) == md5($_POST['bannerid'])){
			$sql = "UPDATE `tbKLabVisits` SET `sVerified` = 1 WHERE `iID` = :id";
			db::Query($sql, array(':id'=>$row['iID']));
		}
	}
	$sql = "SELECT * FROM `tbKLabVisits` WHERE `sVerified` = 0";
	$q = db::Query($sql);
	$row = $q->fetch();
	
	if(isset($row['sBannerID'])){
	?>
	<form action="" method="POST">
	<table>
		<tr>
	    	<td>Student Name:</td>
	        <td><?php echo $row['sName'] ?></td>
	    <tr>
	    <tr>
	    	<td>Banner ID:</td>
	        <td><input type="text" name="bannerid" /></td>
	   	</tr>
	    <tr>
	    	<td>&nbsp;</td>
	        <td><input type="submit" value="Verify" /></td>
	    </tr>
	</table>
	</form>
	<?php
	}else{
			if(isset($_POST['action'])){
				$sql = "UPDATE `tbConfig` SET `sValue` = 'true' WHERE `sVariable` = 'sOpen'";
				db::Query($sql);
			}
			$sql = "SELECT * FROM `tbConfig` WHERE `sVariable` = 'sOpen'";
			$q = db::Query($sql);
			$r = $q->fetch();
			if($r['sValue'] == 'true'){
				echo 'Waiting For User Login...';
			}else{
				?>
                <form action="" method="POST">
                	Click the button below once you have the students ID in your hand.<br/>
                    <input type="hidden" name="action" value="open" />
                	<input type="submit" value=" Open Sign In " style="font-size:18px"  />
                </form>
                <?php
			}
	}
	?>
    <br/>
    <br/>
	</td>
	</tr>
	<tr>
    	<td>
        <h4>K-103 Business Lab Statistics</h4>
	 <iframe src='http://internal.edison.edu/k103/stats.php' style='width:100%; height:75px' frameborder=0 scrolling='no'></iframe>
        <br/><br/>
        <?php if($USER['sLevel'] == 'Administrator' or $USER['sLevel'] == 'Super Administrator'){ ?>
        <h4>Semester System Resets</h4>
        <center><input type="button" value=" Reset For New Semester " onclick="window.location = 'K103_Reset.php'" /></center>
        <?php } ?>
        </td>
    </tr>
</table>
</p>
<?php
include("template_bot.php");
?>